﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcWeb.Models;
using System.Web.Security;
using SailHero.Soft.FrameWork.IDomainRepositories.Contracts;
using UI.Web.SailHeroSoftAuthorization.Helper;

namespace MvcWeb.Controllers
{
    [Export(typeof(IController)), ExportMetadata("Name", "Login")]
    public class LoginController : Controller
    {
        /// <summary>
        /// 数据操作接口
        /// </summary>
        [Import]
        public ISys_UserRepository UserModel;

        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(string UserAccount, string Password)
        {
            var user = UserModel.FirstOrDefault(model => model.ACCOUNT == UserAccount && model.PASSWORD == Password);
            if (user != null)
            {
                FormsAuthentication.SetAuthCookie(UserAccount, true);
                Session["user"] = user;
                return RedirectToAction("Index", "AuthHome");
            }
            else
            {
                ViewData["LoginErr"] = "用户名或密码错误！";
                return View();
            }

        }


    }
}
